<?php
/**
 * Created by 荣耀电竞.
 * User: 林子彦 <278805354@qq.com>
 * Date: 2018/6/13 0013
 * Time: 10:01
 */
namespace App\Admin\Models;
use App\Admin\Contracts\MemberInterface;
use App\Base\Models\BaseModel;

class  ActionLogModel extends  BaseModel {
    /**
     * 表名
     * @var string
     */
    public $table="action_log";
    /**
     * 时间自动
     * @var bool
     */
    public $timestamps=true;
    /**
     * The name of the "created at" column.
     *
     * @var string
     */
    const CREATED_AT = 'create_time';  //修改添加时间字段
    /**
     * The name of the "updated at" column.
     *
     * @var string
     */
    const UPDATED_AT = 'update_time';
    /**
     * 模型的日期字段保存格式。
     */
    protected $dateFormat = 'U';

   protected $appends = ["action_name","username","ip_info"];//,"username","action_info"

    /**
     * @return ActionModel
     */
    public function getActionModel(){
        return app()->make(ActionModel::class);
    }

    /**
     * 用户接口
     * @return MemberInterface
     */
    public function getMemberInterface(){
        return app()->make(MemberInterface::class);
    }


    public function getActionNameAttribute(){
        $actionId=$this->action_id;
        $info=$this->getActionModel()->newQuery()->where("id",$actionId)->first();
        return $info["title"]??"";
    }
    public function getUsernameAttribute(){
        $userId=$this->user_id;
        return $this->getMemberInterface()->getAccountByUid($userId);
    }
    public function getIpInfoAttribute(){
        $ip=$this->action_ip;
        return long2ip($ip);
    }




}